package com.leyou.auth.config;


import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.leyou.auth.interceptors.LoginInterceptors;
import com.leyou.auth.utils.JwtUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@SuppressWarnings("ALL")
/**
 * @Description :
 * @author     :LD
 */
public class MvcConfiguration implements WebMvcConfigurer {
    private JwtUtils jwtUtils;
    private ClientProperties properties;

    public MvcConfiguration(@Lazy JwtUtils jwtUtils, ClientProperties properties) {
        this.jwtUtils = jwtUtils;
        this.properties = properties;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册拦截器，得到拦截器注册器
        InterceptorRegistration registration = registry.addInterceptor(new LoginInterceptors(jwtUtils));
        //配置拦截路径
        if (!CollectionUtils.isEmpty(properties.getIncludeFilterPaths())){
            registration.addPathPatterns(properties.getIncludeFilterPaths());
        }
        //配置放行路径
        if (!CollectionUtils.isEmpty(properties.getExcludeFilterPaths())){
            registration.excludePathPatterns(properties.getExcludeFilterPaths());
        }
    }
}
